package com.ruoyi.project.projectCategory.controller;

import java.util.List;

import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.SysUser;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.projectCategory.domain.ProjectCategory;
import com.ruoyi.project.projectCategory.service.IProjectCategoryService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.domain.Ztree;

/**
 * projectCategoryController
 *
 * @author xzshan
 * @date 2020-05-26
 */
@Controller
@RequestMapping("/project/projectCategory")
public class ProjectCategoryController extends BaseController
{
    private String prefix = "project/projectCategory";

    @Autowired
    private IProjectCategoryService projectCategoryService;

    @RequiresPermissions("project:projectCategory:view")
    @GetMapping()
    public String projectCategory()
    {
        return prefix + "/projectCategory";
    }

    /**
     * 查询projectCategory树列表
     */
    @RequiresPermissions("project:projectCategory:list")
    @PostMapping("/list")
    @ResponseBody
    public List<ProjectCategory> list(ProjectCategory projectCategory)
    {
        List<ProjectCategory> list = projectCategoryService.selectProjectCategoryList(projectCategory);
        return list;
    }

  @PostMapping("/page")
  @ResponseBody
  public TableDataInfo page(ProjectCategory projectCategory)
  {
    startPage();
    List<ProjectCategory> list = projectCategoryService.selectProjectCategoryList(projectCategory);
    return getDataTable(list);
  }
    /**
     * 导出projectCategory列表
     */
    @RequiresPermissions("project:projectCategory:export")
    @Log(title = "projectCategory", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProjectCategory projectCategory)
    {
        List<ProjectCategory> list = projectCategoryService.selectProjectCategoryList(projectCategory);
        ExcelUtil<ProjectCategory> util = new ExcelUtil<ProjectCategory>(ProjectCategory.class);
        return util.exportExcel(list, "projectCategory");
    }

    /**
     * 新增projectCategory
     */
    @GetMapping(value = { "/add/{id}", "/add/" })
    public String add(@PathVariable(value = "id", required = false) Long id, ModelMap mmap)
    {
        if (StringUtils.isNotNull(id))
        {
            mmap.put("projectCategory", projectCategoryService.selectProjectCategoryById(id));
        }
        return prefix + "/add";
    }

    /**
     * 新增保存projectCategory
     */
    @RequiresPermissions("project:projectCategory:add")
    @Log(title = "projectCategory", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProjectCategory projectCategory)
    {
        return toAjax(projectCategoryService.insertProjectCategory(projectCategory));
    }

    /**
     * 修改projectCategory
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ProjectCategory projectCategory = projectCategoryService.selectProjectCategoryById(id);
        mmap.put("projectCategory", projectCategory);
        return prefix + "/edit";
    }

    /**
     * 修改保存projectCategory
     */
    @RequiresPermissions("project:projectCategory:edit")
    @Log(title = "projectCategory", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProjectCategory projectCategory)
    {
        return toAjax(projectCategoryService.updateProjectCategory(projectCategory));
    }

    /**
     * 删除
     */
    @RequiresPermissions("project:projectCategory:remove")
    @Log(title = "projectCategory", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{id}")
    @ResponseBody
    public AjaxResult remove(@PathVariable("id") Long id)
    {
        return toAjax(projectCategoryService.deleteProjectCategoryById(id));
    }

    /**
     * 选择projectCategory树
     */
    @GetMapping(value = { "/selectProjectCategoryTree/{id}", "/selectProjectCategoryTree/" })
    public String selectProjectCategoryTree(@PathVariable(value = "id", required = false) Long id, ModelMap mmap)
    {
        if (StringUtils.isNotNull(id))
        {
            mmap.put("projectCategory", projectCategoryService.selectProjectCategoryById(id));
        }
        return prefix + "/tree";
    }

    /**
     * 加载projectCategory树列表
     */
    @GetMapping("/treeData")
    @ResponseBody
    public List<Ztree> treeData()
    {
        List<Ztree> ztrees = projectCategoryService.selectProjectCategoryTree();
        return ztrees;
    }
}
